<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
     str = 'hello world';
     var start=0;
     var count=0;
    while(true){
      var index = str.indexOf('l',start)
       if(index===-1){
         break;
       }
       // 循环一次 加1 能够循环一次，就说明找到一个
       count++;
       // 跨过找到的元素继续往后找
       start=index+1
     }
     console.log(count)
    
  </script>
</body>
</html>